function formatDate(date) {    
	    var myyear = date.getFullYear();   
	    var mymonth = date.getMonth()+1;   
	    var myweekday = date.getDate();    
	       
	    if(mymonth < 10){   
	        mymonth =  mymonth;   
	    }    
	    if(myweekday < 10){   
	        myweekday = myweekday;   
	    }   
	    return (myyear+"-"+mymonth + "-" + myweekday);    
	}   
	 //获得某月的天数
	 function getMonthDays(myMonth,nowYear){   
	     var monthStartDate = new Date(nowYear, myMonth, 1);    
	     var monthEndDate = new Date(nowYear, myMonth + 1, 1);    
	     var   days   =   (monthEndDate   -   monthStartDate)/(1000   *   60   *   60   *   24);    
	     return   days;    
	 }   
class Cander {
    constructor() {
        this.monthDay = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
        this.thead = [
            {"id": "1", "name": "一"},
            {"id": "2", "name": "二"},
            {"id": "3", "name": "三"},
            {"id": "4", "name": "四"},
            {"id": "5", "name": "五"},
            {"id": "6", "name": "六"},
            {"id": "7", "name": "七"},
        ];//定义表格头部数据
    }

    /**
     * 获取课程日历
     * 创建日历
     */
    getDate() {
        let monthData = JSON.parse(localStorage.getItem("dates"));//课程数据
        for (let i in monthData) {
            for (let j in monthData[i]) {
                let year = i;
                let month = j;
                this.create_tbody(year, month, this.whatDay(year, month), monthData[i][j]);//创建日历的身体部分
            }
        }
    }
    /**
 * 判断某年是否是闰年
 * @param year年
 *
 */
	isLeap(year) {
		if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
			return true;
		}
		else {
			return false;
		}
	}

	/**
	 * 下一个月的数据
	 */
	nextMonth() {
		var now=new Date();
		var year = now.getFullYear();//getYear()+1900=getFullYear()
		var month = now.getMonth() +1;//0-11表示1-12月
		var day = now.getDate();
		if(parseInt(month)<10){
			month="0"+month;
		}
		if(parseInt(day)<10){
			day="0"+day;
		}
		now =year + '-'+ month + '-' + day;
				// 下月信息
		let lastMonth = parseInt(month)+1
		if(parseInt(lastMonth) >12){
				lastMonth ='01'
		}
		 var  lastSize= new Date(year, parseInt(lastMonth), 0).getDate();//下月总天数
				//如果是12月份，则取下一年的1月份 
		 if(parseInt(month)==12){ 
				 return (parseInt(year) + 1) + '-01-' + day;
		}
		//下月总天数<本月日期，比如1月的31日，在2月中没有30
		 if (parseInt(lastSize) < parseInt(day)) {
					return year + '-' + lastMonth+'-'+ lastSize;
				}else{
				  // 正常情况下
				  return year + '-' + lastMonth+'-'+ day;
				}
	}

	/**
	 * 这是上一个月的数据
	 */
	preMonth() {
		var now=new Date();
		var year = now.getFullYear();//getYear()+1900=getFullYear()
		var month = now.getMonth() +1;//0-11表示1-12月
		var day = now.getDate();
		if(parseInt(month)<10){
			month="0"+month;
		}
		if(parseInt(day)<10){
			day="0"+day;
		}
		let  preMonth =parseInt(month)-1
		if(parseInt(preMonth) <1){
		  preMonth ='12'
		}
		  var  preSize= new Date(year, parseInt(preMonth), 0).getDate();//上月总天数
		  // 如果是1月份  则为上一年的12月，年份退一年
		  if(parseInt(month)== 1){ 
			return (parseInt(year) - 1) + '-12-' + day;
		 }
		  //上月总天数<本月日期，比如3月的31日，在2月中没有31
		  if (parseInt(preSize) < parseInt(day)) {
		    return year + '-' + preMonth+'-'+ preSize;
		}else{
		  // 正常情况下
		  return year + '-' + preMonth+'-'+ day;
		}


		
	}
	 /**
	 * 判断某年某月某日是星期几，默认日为0
	 * @param year
	 * @param month
	 * @param day
	 * @returns {number}
	 */
	whatDay(date) {
		var weekArray = new Array("日", "一", "二", "三", "四", "五", "六");
		  var week = weekArray[new Date(date).getDay()];//注意此处必须是先new一个Date
		  return week;
	}
	
	//获取AddDayCount天后的日期
	getDateStr(AddDayCount,type){
		var dd = new Date();
		if(type=='pre'){
			dd.setDate(dd.getDate()- AddDayCount);
		}else if(type=='next'){
			dd.setDate(dd.getDate()+AddDayCount);
		}
		//dd.setDate(dd.getDate()+AddDayCount);
		var y = dd.getFullYear();
		var m = dd.getMonth()+1;//获取当前月份的日期
		var d = dd.getDate();
		return y+'-'+(m<10?'0'+m:m)+'-'+d;
	}
	
	/**获取本月最后一天**/
	getCountDays(){
	  var curDate = new Date();
	  var curMonth = curDate.getMonth();
	  curDate.setMonth(curMonth + 1); 
	  curDate.setDate(0);
	  return curDate.getDate();
	}
	
	
	// 下个月的日期（最后一天）
	getCountDays1(){
		var curDate = new Date();
		var curMonth = curDate.getMonth();
		curDate.setMonth(curMonth + 2);
		curDate.setDate(0);
		return curDate.getDate();
	}
	
	getWeekArr(m){
		var stamp = new Date().getTime()
		  var day = ''
		  var arr = []
		  for(let i = 0 ; i<=m -1 ; i++){
			let day = new Date(stamp + 24 * 3600000 * i)
			// console.log(day.getDay())
			let week = this.getWeek(day.getDay())
			arr.push(week)
		  }
		  return arr
	}
	
	getWeek(e){
		var nowWeek = ''
		  var weekday = []
		  weekday[0] = "周日";
		  weekday[1] = "周一";
		  weekday[2] = "周二";
		  weekday[3] = "周三";
		  weekday[4] = "周四";
		  weekday[5] = "周五";
		  weekday[6] = "周六";
		  return weekday[e]
	}
	
	
	  
	//获得本季度的开始月份   
	// getQuarterStartMonth(){   
	//     var quarterStartMonth = 0;   
	//     if(nowMonth<3){   
	//        quarterStartMonth = 0;   
	//     }   
	//     if(2<nowMonth && nowMonth<6){   
	//        quarterStartMonth = 3;   
	//     }   
	//     if(5<nowMonth && nowMonth<9){   
	//        quarterStartMonth = 6;   
	//     }   
	//     if(nowMonth>8){   
	//        quarterStartMonth = 9;   
	//     }   
	//     return quarterStartMonth;   
	// }   
	  
	//获得本周的开始日期   
	// getWeekStartDate() {    
	//     var weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek);    
	//     return formatDate(weekStartDate);   
	// }    
	  
	// //获得本周的结束日期   
	// getWeekEndDate() {    
	//     var weekEndDate = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek));    
	//     return formatDate(weekEndDate);   
	// }    
	  
	//获得本月的开始日期   
	getMonthStartDate(nowYear,nowMonth){   
	    var monthStartDate = new Date(nowYear, nowMonth, 1);    
	    return formatDate(monthStartDate);   
	}   
	  
	//获得本月的结束日期   
	getMonthEndDate(nowYear,nowMonth){   
	    var monthEndDate = new Date(nowYear, nowMonth, getMonthDays(nowMonth,nowYear));    
	    return formatDate(monthEndDate);   
	}   
	  
	//获得本季度的开始日期   
	// getQuarterStartDate(){   
	       
	//     var quarterStartDate = new Date(nowYear, getQuarterStartMonth(), 1);    
	//     return formatDate(quarterStartDate);   
	// }   
	  
	// //或的本季度的结束日期   
	// getQuarterEndDate(){   
	//     var quarterEndMonth = getQuarterStartMonth() + 2;   
	//     var quarterStartDate = new Date(nowYear, quarterEndMonth, getMonthDays(quarterEndMonth));    
	//     return formatDate(quarterStartDate);   
	// }   
	
	
	/**
	 * 获取当前日期为本月的第几周
	 * @param a 当前日期的年
	 * @param b 当前日期的月
	 * @param c 当前日期日
	 */
	getYearWeek (a, b, c){
	  /*  
		date1是当前日期  
		date2是当年第一天  
		d是当前日期是今年第多少天  
		用d + 当前年的第一天的周差距的和在除以7就是本年第几周  
		*/
		var date1 = new Date(a, parseInt(b) - 1, c),
			date2 = new Date(a, 0, 1),
			d = Math.round((date1.valueOf() - date2.valueOf()) / 86400000);
		return Math.ceil((d + ((date2.getDay() + 1) - 1)) / 7);
	}
	
	getEveryDay(AddDayCount=''){
		var curDate = new Date();
		  var nowDate = new Date().getDate()
		  var n = curDate.getMonth();
		  var m = n
		  n = n + 1;
		  m = n + 1;
		  if(n < 10){
		    n = `0${n}`
		  }
		  if (m < 10) {
		    m = `0${m}`
		  }
		  var dayArry = [];
		  var day = this.getCountDays();
		   
		  let weekArr =  this.getWeekArr(day)
		  for (var k = 1; k <= day; k++) {
		    if (k >= nowDate){
		      if(k < 10){
		        k = `0${k}`
		      }
		      dayArry.push(`${n}-${k}`);
		    }
		  }
		  var day2 = this.getCountDays1();
		  for (var i = 1 ; i <= day2 ; i++){
		    if (dayArry.length <= 30){
		      if (i < 10) {
		        i = `0${i}`
		      }
		      dayArry.push(`${m}-${i}`);
		    }
		  }
		  let arr = []
		  let parame = AddDayCount?AddDayCount:day-1
		  for (let i=0; i<=parame ; i++){
		    arr.push({ label: dayArry[i], date: weekArr[i],value:i,completedate:(curDate.getFullYear()+'-'+dayArry[i])})
		  }
		  for(let i=0 ;i<arr.length ; i++){
		    arr[0].date = '今天'
		    arr[1].date = '明天'
		    arr[2].date = '后天'
		  }
		  return arr;
	}
	
	/**
	* 实现一个月有几周以及每周开始时间和结束时间
	* @param year
	* @param month
	*/
	getweekdata(year, month){
		var new_year = year;    //取当前的年份
		var new_month = month++;//取下一个月的第一天，方便计算（最后一天不固定）
		var weekDay = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天"];
	
		if (month > 12) {
			new_month -= 12;        //月份减
			new_year++;            //年份增
		}
		var first_date = new Date(new_year, new_month, 1);                //取当年当月中的第一天-时间格式
		var last_Data = (new Date(first_date.getTime() - 1000 * 60 * 60 * 24)).getDate() //获取当月最后一天日期
		//console.log('最后一天日期'+last_Data+'号')
		//当月第一天是周几
		var firstzhouji = new Date(new_year + '/' + new_month + '/' + 1).getDay() == 0 ? '星期天' : weekDay[new Date(new_year + '/' + new_month + '/' + 1).getDay() - 1]
		//当月最后一天是周几
		var lastzhouji = new Date(new_year + '/' + new_month + '/' + last_Data).getDay() == 0 ? '星期天' : weekDay[new Date(new_year + '/' + new_month + '/' + last_Data).getDay() - 1]
	
		var firsttime = '' //第一周有几天
		if (firstzhouji == '星期一') { firsttime = 7 }
		if (firstzhouji == '星期二') { firsttime = 6 }
		if (firstzhouji == '星期三') { firsttime = 5 }
		if (firstzhouji == '星期四') { firsttime = 4 }
		if (firstzhouji == '星期五') { firsttime = 3 }
		if (firstzhouji == '星期六') { firsttime = 2 }
		if (firstzhouji == '星期天') { firsttime = 1 }
		//console.log('本月第一天“'+firstzhouji+'”本月第一周有“'+firsttime+'”天')
	
		var lasttime = '' //最后一周有几天
		if (lastzhouji == '星期一') { lasttime = 1 }
		if (lastzhouji == '星期二') { lasttime = 2 }
		if (lastzhouji == '星期三') { lasttime = 3 }
		if (lastzhouji == '星期四') { lasttime = 4 }
		if (lastzhouji == '星期五') { lasttime = 5 }
		if (lastzhouji == '星期六') { lasttime = 6 }
		if (lastzhouji == '星期天') { lasttime = 7 }
		// console.log('本月最后一天“'+lastzhouji+'”本月最后一周有“'+lasttime+'”天')
	
		// 前后两周  加上 剩余周数  得出总周数
		var contime = 2 + (last_Data - lasttime - firsttime) / 7
	
		//得出每周对应的日期
		var zhouArry = []
	
	
		for (var i = 1; i <= contime; i++) {
			var strTime = ''
			var lastTime = ''
			if (i == 1) {
				strTime = year + '-' + new_month + '-' + 1
				lastTime = year + '-' + new_month + '-' + (1 + firsttime - 1)
			} else if (i == contime) {
				strTime = year + '-' + new_month + '-' + (last_Data - lasttime + 1)
				lastTime = year + '-' + new_month + '-' + last_Data
			} else {
				strTime = addDate(zhouArry[zhouArry.length - 1].endtime, 1)
				lastTime = addDate(zhouArry[zhouArry.length - 1].endtime, 7)
			}
	
			
	
			zhouArry.push({
				weeknum: '0'+i,
				weeks:i,
				begintime: strTime,
				endtime: lastTime,
			})
		
		
		
		    //日期增加 接受两个参数， 传入的时间，传入时间增加的天数
		    function addDate(date, days) {
		        if (days == undefined || days == '') {
		            days = 1;
		        }
		
		        var date = new Date(date);
		        date.setDate(date.getDate() + days);
		        var month = date.getMonth() + 1;
		        var day = date.getDate();
		
		        return date.getFullYear() + '-' + month + '-' + day;
		    }
		
		
		    //console.log(zhouArry)//打印数据
		    
		
		    }
		    return zhouArry
	}
	
}

export default Cander